package com.shengxian.basic.mylogin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.shengxian.basic.mylogin.entity.baseinfo;
import com.shengxian.basic.mylogin.entity.biaoqian;
import com.shengxian.basic.mylogin.mapper.biaoqianmapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(description = "标签管理")
@RestController
@RequestMapping("/biaoqian")
@CrossOrigin
@Slf4j
public class biaoqiancontroller {

    @Autowired
    private biaoqianmapper mybiaoqianmapper;

    @ApiOperation(value = "查找所有标签 ")
    @PostMapping("findbiaoqian")
    public String findAllTeacher(@RequestBody biaoqian mybiaoqian) {
        QueryWrapper<biaoqian> queryWrapper = new QueryWrapper();
        queryWrapper
                .eq("biaoqianid", mybiaoqian.getBiaoqianid())
                .eq("name", mybiaoqian.getName()).or()
                .eq("level", mybiaoqian.getLevel());


        List<biaoqian> mybiaoqian2 = mybiaoqianmapper.selectList(queryWrapper);
        log.info(" == " + mybiaoqian2);
        return mybiaoqian2.toString();

    }


    @ApiOperation(value = "增加标签")
    @PostMapping("addbiaoqian")
    public void adduser(@RequestBody biaoqian mybiaoqian) {
        Map<String, Object> mymap = new HashMap<>();
        mymap.put("biaoqianid", mybiaoqian.getBiaoqianid());
        List<biaoqian> baseinfo2 = mybiaoqianmapper.selectByMap(mymap);
        if (baseinfo2.isEmpty()) {
            log.info(" 没有    可以添加 ");
            mybiaoqianmapper.insert(mybiaoqian);
        } else {
            log.info(" 已经有  不能添加 ");
        }

    }


    @ApiOperation(value = " 修改标签")
    @PostMapping("updatebiaoqian")
    public void updateuser(@RequestBody biaoqian mybiaoqian) {

        UpdateWrapper<biaoqian> updateWrapper = new UpdateWrapper();
        updateWrapper.set("name", mybiaoqian.getName())
                .set("level", mybiaoqian.getLevel())
                .eq("biaoqianid", mybiaoqian.getBiaoqianid());
        mybiaoqianmapper.update(null, updateWrapper);

    }


    @ApiOperation(value = " 删除标签")
    @PostMapping("deletebiaoqian")
    public void deleteuser(@RequestBody biaoqian mybiaoqian) {
        log.info(" 删除用户");
        QueryWrapper<biaoqian> queryWrapper = new QueryWrapper();
        queryWrapper.eq("biaoqianid", mybiaoqian.getBiaoqianid());

        int count = mybiaoqianmapper.delete(queryWrapper);
        System.out.println(count);

    }


}
